<template>
  <div class="body-content">
    <div id="magazine" v-if="bookImgs && bookImgs.length" ref="magazine">
      <div v-for="(item, index) in bookImgs" :key="index">
        <div class="page" v-if="isShow" ref="page">
          <img class="img_full" :src="item.img" alt="" ref="bookImg">
        </div>
      </div>
    </div>
    <!-- <div v-show="!isShow" class="loading_box">
      <div class="loading">
        <spinner />
      </div>
    </div> -->
  </div>
</template>
<script>
  import $ from "jquery";
  import turn from "../plugin/turn/lib/turn"
  import Spinner from 'vue-simple-spinner'

  export default {
    name: "TurnCom",
    components: { Spinner },
    props: {
      bookImgs: {
        type: Array,
        default: () => []
      }
    },
    data() {
      return {
        isShow: false,
        value: "",
        page: 1
      };
    },
    mounted() {
      setTimeout(() => {
          this.isShow = true
          $("#magazine").turn("center");
          $("#magazine").turn("page");

          this.initTurn()
      }, 1000)
    },

    methods: {
      initTurn() {
        let self = this
        $("#magazine").turn({
            display: "double",
            elevation: 0,                       // 转换期间页面的高度
            duration: 1200,
            gradients: true,
            autoCenter: true,
            acceleration: true,
            page: self.page,
            // width: 600
        });
      },

      // 缩放图片
      changeImg(o) {
        let wheelVal = o.wheelDelta
        console.log('wheelVal : ', wheelVal);
        
        for (let i in this.$refs.page) {
          if (wheelVal > 0) { 
            this.$refs.magazine.width += `${wheelVal}%`
            this.$refs.magazine.height += `${wheelVal}%`
            this.$refs.page[i].style.height += `${wheelVal}%`
          } else {
            this.$refs.magazine.width -= `${wheelVal}%`
            this.$refs.magazine.height -= `${wheelVal}%`
            this.$refs.page[i].style.height -= `${wheelVal}%`
          }
        }
      }
    }
  };
</script>
<style lang="less" scoped>
body {
  background: #ccc;
}
.body-content {
  padding: 20px 0;
  // border: 1px solid #ccc;
}
.page {
  width: 100%;
  height: 600px;
}
.current-page {
  position: absolute;
  bottom: 0;
  width: 100%;
  text-align: center;
  font-size: 14px;
}
#magazine {
  width: 900px !important;
  height: 600px;
}

#magazine.shadow {
  -webkit-box-shadow: 0 4px 10px #666;
  -moz-box-shadow: 0 4px 10px #666;
  -ms-box-shadow: 0 4px 10px #666;
  -o-box-shadow: 0 4px 10px #666;
  box-shadow: 0 4px 10px #666;
}

#magazine .turn-page {
  background-color: #ccc;
  background-size: 100% 100%;
}
.bookmark {
  // margin-left: 633px;
  font-size: 20px;
  writing-mode: tb-rl;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  // padding-top: 47px;
}
.item:nth-child(2n) {
  background: #ccc;
  width: 45px;
  height: 50px;
}
.item {
  width: 45px;
  height: 160px;
  background: red;
}
.item:nth-child(1) {
  z-index: 4;
  text-shadow: 6px 6px 6px #999;
}
.item:nth-child(2) {
  z-index: 3;
  text-shadow: 6px 6px 6px #333;
}
.item:nth-child(3) {
  z-index: 2;
  text-shadow: 6px 6px 6px #333;
}
.item:nth-child(4) {
  z-index: 1;
  text-shadow: 6px 6px 6px #333;
}

.loading_box {
    width: 100%;
    height: 100%;
    position: relative;
    top: -500px;

    .loading {
        font-size: 60px;
        position: absolute;
        color: #ccc !important;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
    }
}

@media screen and (min-width: 1600px) and (max-width: 1800px) {
  .page { height: 600px; }
  #magazine { width: 930px !important; height: 600px; }
}

@media screen and (min-width: 1400px) and (max-width: 1599px) {
  .page { height: 530px; }
  #magazine { width: 730px !important; height: 530px; }
}

@media screen and (min-width: 1200px) and (max-width: 1399px) {
  .page { height: 450px; }
  #magazine { width: 630px !important; height: 450px; }
}

@media screen and (min-width: 1000px) and (max-width: 1299px) {
  .page { height: 400px; }
  #magazine { width: 530px !important; height: 400px; }
}

@media screen and (min-width: 768px) and (max-width: 999px) {
  .page { height: 400px; }
  #magazine { width: 430px !important; height: 400px; }
}
</style>